#include <stdio.h>

#define SIZE 500

int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    int i, j;
    int a[SIZE] = {0};
    int len = 0;
    int tmp = n < m ? n : m;
    for (i = 1; i <= tmp; i++)
    {
        if (n%i == 0 && m%i == 0)
        {
            a[len] = i;
            len++;
        }
    }
    int len2 = i;
    int sum = 0;
    for (i = 0; i < len; i++)
    {
        sum += a[i];
    }
    printf("%d\n", sum);
    return 0;
}